using PhillyCodeCamp.Domain.Validation;

namespace PhillyCodeCamp.Domain
{
    public abstract class DomainObject : IDomainObject
    {
        private readonly IBusinessRuleSet rules;

        protected DomainObject(IBusinessRuleSet rules)
        {
            this.rules = rules;
            this.rules.AddAttributeValidationRules(this);
        }

        public IBusinessRuleSet Validate()
        {
            return rules.BrokenBy(this);
        }

        public bool IsValid
        {
            get { return Validate().IsEmpty; }
        }
    }
}